<?php
// +----------------------------------------------------------------------
// | author: admin
// +----------------------------------------------------------------------


namespace app\api\controller;


use app\adminapi\controller\BaseAdminController;
use app\api\logic\DriverCredentialLogic;
use app\api\validate\DriverCredentialValidate;


/**
 * DriverCredential控制器
 * Class DriverCredentialController
 * @package app\api\controller
 */
class DriverCredentialController extends BaseApiController
{
    /**
     * @notes 添加
     * @return \think\response\Json
     * @author admin
     * @date 2025/04/25 16:46
     */
    public function add()
    {
        $params = (new DriverCredentialValidate())->post()->goCheck('add');
        $result = DriverCredentialLogic::add($params);
        if (true === $result) {
            return $this->success('添加成功', [], 1, 1);
        }
        return $this->fail(DriverCredentialLogic::getError());
    }

    /**
     * @notes 编辑
     * @return \think\response\Json
     * @author admin
     * @date 2025/04/25 16:46
     */
    public function edit()
    {
        $params = (new DriverCredentialValidate())->post()->goCheck('edit');
        $result = DriverCredentialLogic::edit($params);
        if (true === $result) {
            return $this->success('提交成功', [], 1, 1);
        }
        return $this->fail(DriverCredentialLogic::getError());
    }


    /**
     * @notes 删除
     * @return \think\response\Json
     * @author admin
     * @date 2025/04/25 16:46
     */
    public function delete()
    {
        $params = (new DriverCredentialValidate())->post()->goCheck('delete');
        DriverCredentialLogic::delete($params);
        return $this->success('删除成功', [], 1, 1);
    }


    /**
     * @notes 获取详情
     * @return \think\response\Json
     * @author admin
     * @date 2025/04/25 16:46
     */
    public function detail()
    {
        $params = (new DriverCredentialValidate())->goCheck('detail');
        $result = DriverCredentialLogic::detail($params);
        if($result['car_pic'])
        {
            $result['car_pic'] = json_decode($result['car_pic'], true);
        }

        return $this->data($result);
    }


}